home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * AERRequiredSuite.c
- *
- * Apple Event Registry (AER) Required Suite support
- *
- ****************************************************************************/
-
- #include "Sketch.h"
- #include "AERRequiredSuite.h"
- #include "AppleEvent.h"
- #include "Documents.h"
-
- // Required Suite Event Handlers
-
- static pascal OSErr HandleOAPP (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
- static pascal OSErr HandleQUIT (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
- static pascal OSErr HandleODOC (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
- static pascal OSErr HandlePDOC (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
-
- /*****************************************************************************
- *
- * InstallRequiredSuiteHandlers
- *
- * Called by InstallAEHandlers() at program initialization time
- *
- *****************************************************************************/
-
- Boolean
- InstallRequiredSuiteHandlers()
- {
- Boolean error;
-
- error = AEInstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- NewAEEventHandlerProc(HandleOAPP),
- 0,
- false);
-
- if (error == noErr)
- error = AEInstallEventHandler(kCoreEventClass,
- kAEQuitApplication,
- NewAEEventHandlerProc(HandleQUIT),
- 0,
- false);
-
- if (error == noErr)
- error = AEInstallEventHandler(kCoreEventClass,
- kAEOpenDocuments,
- NewAEEventHandlerProc(HandleODOC),
- 0,
- false);
-
- if (error == noErr)
- error = AEInstallEventHandler(kCoreEventClass,
- kAEPrintDocuments,
- NewAEEventHandlerProc(HandlePDOC),
- 0,
- false);
-
- return (error == noErr);
- }
-
- /*****************************************************************************
- *
- * HandleOAPP
- *
- * AppleEvent processing to open the application
- *
- *****************************************************************************/
-
- static pascal OSErr HandleOAPP(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
- {
- #pragma unused (appleEvent, refCon)
-
- OSErr error = noErr;
- DocumentReference document;
-
- document = MakeNewDocument(NULL);
-
- if (document == nil)
- error = memFullErr;
-
- PutReplyErrorNumber(reply, error);
-
- return error;
- }
-
-
- /*****************************************************************************
- *
- * HandleQUIT
- *
- * AppleEvent processing to quit the application
- *
- *****************************************************************************/
-
- static pascal OSErr HandleQUIT(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
- {
- #pragma unused (reply, refCon)
- OSErr error;
- DescType saveOptions;
- DescType actualType;
- long actualSize;
-
-
- error = AEGetParamPtr(appleEvent,
- keyAESaveOptions,
- typeEnumerated,
- &actualType,
- &saveOptions,
- sizeof(saveOptions),
- &actualSize);
-
- if (error == errAEDescNotFound)
- {
- saveOptions = kAEAsk;
- error = noErr;
- }
-
- if (error == noErr)
- error = DoQuit(saveOptions);
-
- return noErr;
- }
-
- /*****************************************************************************
- *
- * HandleODOC
- *
- * AppleEvent processing to open one or more documents
- *
- *****************************************************************************/
-
- static pascal OSErr HandleODOC(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
- {
- #pragma unused (appleEvent, refCon)
-
- OSErr error = errAEEventNotHandled;
-
- AEPutParamPtr(reply, keyErrorNumber, typeLongInteger, (Ptr)&error, sizeof(OSErr));
-
- return error;
- }
-
- /*****************************************************************************
- *
- * HandlePDOC
- *
- * AppleEvent processing to print one or more documents
- *
- *****************************************************************************/
-
- static pascal OSErr HandlePDOC(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
- {
- #pragma unused (appleEvent, refCon)
-
- OSErr error = errAEEventNotHandled;
-
- AEPutParamPtr(reply, keyErrorNumber, typeLongInteger, (Ptr)&error, sizeof(OSErr));
-
- return error;
- }
-
- // ---------------------------------------------------------------------------------
-
-
-
-